package com.example.pdfdemo

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_file_service.*

/**
 * @author Lmoumou
 * @date : 2019/8/27 14:42
 */
class FileServiceActivity : AppCompatActivity() {

    companion object {

        const val URL = "https://puboss.chengdumaixun.com/article/eaa363a3-ba88-9e20-53d9-c01b1d677f6b.pdf"

        const val OFFICE: Int = 9999
        const val GOOGLE: Int = 9998
        const val MOZILLA: Int = 9997
        fun startThis(context: Context, tag: Int) {
            context.startActivity(Intent(context.applicationContext, FileServiceActivity::class.java).apply {
                putExtra("tag", tag)
            })
        }
    }

    private var tag: Int = OFFICE
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_file_service)
        tag = intent.getIntExtra("tag", OFFICE)


        when (tag) {
            OFFICE -> {
                mWebView.loadUrl("http://view.officeapps.live.com/op/view.aspx?src=$URL")
            }
            GOOGLE -> {
                mWebView.loadUrl("http://docs.google.com/gviewembedded=true&url=$URL")
            }
            MOZILLA -> {
                mWebView.loadUrl("http://mozilla.github.io/pdf.js/web/viewer.html?file=$URL")
            }
        }
    }
}